﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UserFilterTests.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the UserFilterTests type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Tests.Filters
{
    using System.Data.Objects;
    using System.Linq;
    using Data.Filters;
    using Entities;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Tests.Filters.UserFilterTests"/> type.
    /// </summary>
    [TestClass]
    public class UserFilterTests
    {
        /// <summary>
        /// Mock Database
        /// </summary>
        private readonly IObjectSet<User> _mockObjectSet = new MockObjectSet<User>();

        /// <summary>
        /// Initializes a new instance of the <see cref="UserFilterTests"/> class.
        /// </summary>
        public UserFilterTests()
        {
            _mockObjectSet.AddObject(new User { Id = 1, Name = "User 1" });
            _mockObjectSet.AddObject(new User { Id = 2, Name = "User 2" });
        }

        /// <summary>
        /// Filter_s the should return everything if the object to comare is null.
        /// </summary>
        [TestMethod]
        public void UserFilterShouldReturnEverythingIfTheObjectToComareIsNull()
        {
            var result = _mockObjectSet.Filter(null).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
        }

        /// <summary>
        /// Filters the should return everything if the object to comare is uninitialized.
        /// </summary>
        [TestMethod]
        public void UserFilterShouldReturnEverythingIfTheObjectToComareIsUninitialized()
        {
            var result = _mockObjectSet.Filter(new User()).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count());
        }

        /// <summary>
        /// Filters the should return object filtered by id.
        /// </summary>
        [TestMethod]
        public void UserFilterShouldReturnObjectFilteredById()
        {
            var result = _mockObjectSet.Filter(new User { Id = 2 }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual("User 2", result[0].Name);
        }

        /// <summary>
        /// Filters the name of the should return object filtered by.
        /// </summary>
        [TestMethod]
        public void UserFilterShouldReturnObjectFilteredByName()
        {
            var result = _mockObjectSet.Filter(new User { Name = "User 1" }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(1, result[0].Id);
            Assert.AreEqual("User 1", result[0].Name);
        }

        /// <summary>
        /// Filters the should return object filtered by name with different case.
        /// </summary>
        [TestMethod]
        public void UserFilterShouldReturnObjectFilteredByNameWithDifferentCase()
        {
            var result = _mockObjectSet.Filter(new User { Name = "User 2" }).ToList();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
            Assert.AreEqual(2, result[0].Id);
            Assert.AreEqual("User 2", result[0].Name);
        }
    }
}